/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       paint_surface.h

	$Header: /game/paint_surface.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef PAINT_SURFACE_H_INCLUDED
#define PAINT_SURFACE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "abstract_bitmap.h"
#include "shared_ptr.h"
#include "memory_bitmap.h"

typedef t_shared_ptr<t_abstract_bitmap16> t_abstract_bitmap16_ptr;
typedef t_shared_ptr<t_memory_bitmap16> t_memory_bitmap16_ptr;

// ------------------------------------------------------------
// abstract class to facilitate window painting
// ------------------------------------------------------------
class t_paint_surface
{
public:
	t_paint_surface( t_screen_point window_origin, t_screen_rect const& screen_rect, t_memory_bitmap16_ptr bitmap, t_memory_bitmap16_ptr buffer );
	virtual ~t_paint_surface();

	void draw( t_screen_point const& point, t_abstract_bitmap16 const& source, t_screen_rect const& source_rect );
	void draw( t_abstract_bitmap16 const& source, t_screen_rect const& source_rect );
	void draw( t_screen_point const& point, t_abstract_bitmap16 const& source );
	void draw( t_abstract_bitmap16 const& source );
	// draw directly to the surface.  Faster in many cases.
	virtual void              copy_buffer(); // copy paint buffer to screen
	virtual t_abstract_bitmap16_ptr get_bitmap(); // get surface as a 16 bit bitmap
	t_screen_rect             get_rect() const;  // get rectangle to be painted (client coords)
	t_screen_rect const&      get_screen_rect() const; // get rectangle (screen coords)
	t_screen_point const&			get_window_origin() const;
	void											set_screen_rect( t_screen_rect const& rect );
	void                      set_window_origin( t_screen_point const& point );
protected:
	t_screen_point				m_window_origin;
	bool									m_buffer_changed;
	t_screen_rect					m_screen_rect;
  t_memory_bitmap16_ptr m_bitmap;
	t_memory_bitmap16_ptr m_buffer;
};

// ------------------------------------------------------------
// inlines for abstract class to facilitate window painting
// ------------------------------------------------------------
inline t_screen_rect t_paint_surface::get_rect() const
{
	return m_screen_rect - m_window_origin;
}

inline t_screen_rect const& t_paint_surface::get_screen_rect() const
{
	return m_screen_rect;
}

inline void t_paint_surface::draw( t_abstract_bitmap16 const& source, t_screen_rect const& source_rect )
{
	draw( t_screen_point(0,0), source, source_rect );
}

inline void t_paint_surface::draw( t_screen_point const& point, t_abstract_bitmap16 const& source )
{
	draw( point, source, source.get_rect() );
}

inline void t_paint_surface::draw( t_abstract_bitmap16 const& source )
{
	draw( t_screen_point(0,0), source, source.get_rect() );
}

inline t_screen_point const& t_paint_surface::get_window_origin() const
{
	return m_window_origin;
}

inline void t_paint_surface::set_window_origin( t_screen_point const& point )
{
	m_window_origin = point;
}

inline void t_paint_surface::set_screen_rect( t_screen_rect const& rect )
{
	m_screen_rect = rect;
	m_buffer_changed = false;
}

#endif // PAINT_SURFACE_H_INCLUDED